﻿class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            no: '',
            id: 0,
            counts: [],
            start: 1,
            pagesize: 15,
            keyword: "",
            sizelist: [
                '160',
                '165',
                '170',
                '175',
                '180',
                '185',
                '190',
                '195',
                '特体',
            ],
         
            pricelist: [
                '835',
                '610',
                '300',
            ],
            type: 0,
            state: 'ON',
            typehtml: [],
            statehtml: [],
            merchantName: '',
            chosefile: !1,

        };
    }









    export() {

        let { keyword, size, price, cname, sshword } = this.state

        导出用户列表(res => {
            if (res.issuccess == 1) {

                let str = '用户id,注册时间,打卡积分,分享积分,小票获得积分,获取奖品次数,抽奖次数,当前积分\n'
                //`${topname}\n${housename}\n产品类型,高,宽,深度,单价,数量,总价,单位,立面说明,门板材质/柜体材质\n`
                const jsonData = []
                let total = 0;
                let totalcount = 0;

                // <td className="tconter">{((Number(x.height)* Number(x.width))/1000000).toFixed(2)}</td>
                //                                    <td className="tconter">{(Number(x.singleprice)* (((Number(x.height)* Number(x.width))/1000000).toFixed(2))).toFixed(2)}</td>
                res.list.forEach(x => {
                    str += `${x.id},${formatDate(new Date(x.updateDate))},${x.dakatime},${x.sharetime},${x.xiaopiaotime},${x.gifttime},${x.cjcount},${x.jf}\n`
                })
                let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
                let link = document.createElement("a");
                link.href = uri;
                link.download = formatDate(new Date()) + "用户列表.csv";
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
        })

    }









    getdata() {
        let { start, pagesize, keyword, startdate, enddate } = this.state, err = ''
        if (startdate) {
            if (!enddate) {
                err = '结束时间不能为空'
            } else {
                if (new Date(startdate).getTime() > new Date(enddate).getTime()) {
                    err = '开始时间必须小于结束时间'
                } else {
                    startdate = new Date(startdate).getTime() / 1000;
                    enddate = new Date(enddate).getTime() / 1000;
                }
            }
        }
        if (err != "") {
            alert(err)
            return;
        }


        getuserlist({ startdate, enddate, start: start == 0 ? 0 : start - 1, pagesize }, res => {
            let { list, total } = res;
            // let cnamehtml = []
            // cnamehtml.push(<option value={''}>请选择</option>)
            if (start == 1) {
                let pagecount = Math.ceil(total / pagesize);
                this.setpager(pagecount, start);
                this.setState({ start })
            }
            this.setState({ list, total })
        })

    }



    componentDidMount() {
        let that = this
        this.getdata()
        console.log(laydate, 'laydatelaydate');
        laydate.render({
            elem: '#test1', //指定元素
            type: 'datetime',
            done: function (value, date, endDate) {
                console.log(value, 'startdate');
                that.setState({ startdate: value })
            }
        });
        laydate.render({
            elem: '#test2', //指定元素
            type: 'datetime',
            done: function (value, date, endDate) {
                that.setState({ enddate: value })
            }
        });

        $('.modal1').hide()
        // testdingcan(res=>{
        // })
        this.setState({ showloading: '' })
        // this.freshlist()

    }




    setpager(pagecount, start) {
        let counts = [];
        for (let i = 0; i < pagecount; i++) {
            counts.push(start + i)
        }
        this.setState({ counts, pagestart: 0 })
    }
    clickpage(e) {
        let { pagesize } = this.state
        this.setState({ pagestart: e, start: e * pagesize + 1 }, () => {
            this.getdata()
        })
        console.log(e, 'eee');

        // if(start==e){
        //     start+=pagesize;
        // }else{
        //     start =start+ e*pagesize
        // }

        // this.setState({ pagestart: e, start }, () => {
        //    this.getdata()
        // })
    }
    setpage(e) {
        let { pagesize, start } = this.state
        pagesize = parseInt(e)
        start = 1
        this.setState({ pagesize, start }, () => {
            // 
            this.getdata()
        })
    }
    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }

    search() {
        this.setState({ start: 1 }, () => {
            this.getdata()
        })
    }
    closemodal() {
        $('.modal1').hide()
    }

    reset() {
        this.setState({ state: 'ON', no: '' }, () => {
            this.freshlist()
        })
    }
    selectchange(prop, e) {
        this.setState({ [prop]: e.target.value }, () => {
            this.search()
        })
    }

    del(id) {

        var a = confirm('确定要删除吗?'), that = this
        if (a) {
            删除信息(id, res => {
                if (res.success == 1) {
                    that.getdata()
                }
            })
        }
    }

    render() {
        let { list, startdate, enddate } = this.state;

        return (
            <div className="breadLinebox">
                <div class="alertarea" id='alsucc' >
                </div>


                <Loading hidden={this.state.showloading != 'ON'} />
                <div className='panel-default content_wrap'>
                    <div className="breadLine ">

                        <div className="bbtn">
                            
                          
                            {/* <p className="button l" onClick={this.export.bind(this)} >全部导出</p> */}

                            {/* <div className="inputbox">
                                <input type="text" id="test1" placeholder='请选择开始日期' value={startdate} className="input" />
                                <span>-</span>
                                <input type="text" id="test2" placeholder='请选择结束日期' value={enddate} className="input" />
                            </div> */}
                            {/* <p className="button l" onClick={() => {
                                this.getdata()
                            }} >确定</p> */}

                            {/* <p className="button l" onClick={()=>{
                             $('#file1').click();
                        }} >导入表格</p>
                        <p className="button l" onClick={
                            ()=>{
                                window.location.href='https://techcherry.cn/caiwuapi/temp/信息导入模板.xls'
                            }

                        } >下载模板</p> */}
                        </div>

                        {/* <input type="file" id='file1' onChange={this.filechange.bind(this)} style={{ display: "none" }} /> */}

                    </div>


                    <div className="contentBox">

                        <table className="tab">
                            <thead>
                                <tr>
                                    <th className="tconter">用户id</th>
                                    <th className="tconter">注册时间</th>
                                    <th className="tconter">电话号</th>
                                    <th className="tconter">联名酒</th>
                                    <th className="tconter">腾讯季卡</th>
                                    <th className="tconter">钥匙扣</th>
                                    {/* <th className="tconter">操作</th> */}
                                    {/* <th>是否新人专享</th>
                                    <th>是否会员专享</th> */}
                                </tr>
                            </thead>
                            <tbody>
                                {
                                    list.map((x, i) => {
                                        return (
                                            <tr key={i}>
                                                <td className="tconter">{x.id}</td>
                                                <td style={{ width: '120px' }}>{formatDate(new Date(x.updateDate))}</td>
                                                <td className="tconter">{x.phone}</td>
                                                <td className="tconter">{x.wine}</td>
                                                <td className="tconter">{x.tx}</td>
                                                <td className="tconter">{x.zb}</td>
                                                {/*  <td className="tconter">
                       

                            <p style={{'color':'red','text-decoration':'underline','cursor':"pointer"}}
                             onClick={this.del.bind(this,x.id)}>删除</p> 
                        </td>*/}


                                            </tr>
                                        )
                                    })
                                }
                            </tbody>
                        </table>
                        {this.state.wulist}
                        <div className="pagerbox">
                            <p>共{this.state.total}条</p>
                            <Pager counts={this.state.counts} click={this.clickpage.bind(this)} change={this.setpage.bind(this)} index={this.state.pagestart} />
                        </div>
                    </div>

                </div>
            </div>


        )


    }
}

ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='list' height='list' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)